import static org.junit.Assert.*;

import java.util.List;
import java.util.Map;

import junit.framework.TestCase;

import org.junit.Test;

import com.infinitegroup.findmystuff.models.Account;
import com.infinitegroup.findmystuff.presenters.LoginPresenter;
import com.infinitegroup.findmystuff.views.LoginView;

/**
 * Tests the login logic through the attemptLogin method in the LoginPresener.
 * @author Maria
 *
 */
public class MariaLoginTest extends TestCase{
	
	mockAccount account;
	LoginPresenter presenter;

	@org.junit.Before public void setUp(){
		account = new mockAccount("Burdell", "password", true);
		presenter = new LoginPresenter(new mockView(), account); 
		
	}
		
	//Test for null inputs
	@Test(timeout = 2000)
	public void testNulls() {
		boolean returnValue = presenter.attemptLogin(null, null);
		assertEquals("Passing nulls into the parameter should return false", returnValue, false);
	}
	
	//Test for correct password for an unlocked account
	@Test(timeout = 2000)
	public void testUnlocked1() {
		boolean returnValue = presenter.attemptLogin("Burdell", "password");
		assertEquals("Passing correct password into the parameter for an unlocked account should return true", returnValue, true);
	}
	
	//Test for incorrect password for an unlocked account
	@Test(timeout = 2000)
	public void testUnlocked2() {
		boolean returnValue = presenter.attemptLogin("Burdell", "wrong");
		assertEquals("Passing incorrect password into the parameter for an unlocked accoun should return false", returnValue, false);
	}
	
	//Test for correct password for a locked account
	@Test(timeout = 2000)
	public void testLocked1() {
		account.setActive(false);
		boolean returnValue = presenter.attemptLogin("Burdell", "password");
		assertEquals("Passing correct paaword into the parameter for a locked account should return false", returnValue, false);
	}
	
	//Test for incorrect password for a locked account
	@Test(timeout = 2000)
	public void testLocked2() {
		account.setActive(false);
		boolean returnValue = presenter.attemptLogin("Burdell", "wrong");
		assertEquals("Passing incorrect paaword into the parameter for a locked account should return false", returnValue, false);
	}
	
	//Test for a username that doesn't exist
	public void testNoAccount() {
		account.setActive(false);
		boolean returnValue = presenter.attemptLogin("George", "password");
		assertEquals("Passing into the parameter for a nonexistant account should return false", returnValue, false);
	}

}

/**
 * Creates a class that implements the account inteface so the method could
 * be tested.
 * 
 */
class mockAccount implements Account{
	private String username;
	private String password;
	private boolean active;
	
	mockAccount(String username, String password, Boolean active){
		this.username = username;
		this.password = password;
		this.active = active;
	}
	
	public void setUsername(String username){
		this.username = username;
	}
	
	public void setActive(Boolean active){
		this.active = active;
	}
	
	public void setPassword(String passwrod){
		this.password = password;
	}
	
	@Override
	public void deactivate() {
		active = false;	
	}

	@Override
	public boolean isActive() {
		return active;
	}

	@Override
	public boolean isAdmin() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean changePassword(String newPassword) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean register(String firstName, String lastName, String username,
			String password, String email, String phone, String zipCode) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public long deleteItem(String itemid) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getFirstName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getLastName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public String getEmail() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getUsername() {
		return username;
	}

	@Override
	public String getPhone() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getZipcode() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String request(String itemID) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void checkSuperAdmin() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean exists(String username) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void refresh(String username) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Map<String, String>> getAccountItems() {
		// TODO Auto-generated method stub
		return null;
	}
	
}

/**
 * Makes an unused class that implements the LoginView interface so the method
 * could be tested.
 *
 */
class mockView implements LoginView{

	@Override
	public void advanceToHome(String username) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void advanceToAdminHome(String adminUsername) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void retry() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void advanceToLocked() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void advanceToRegistration() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void displayMessage(String string) {
		// TODO Auto-generated method stub
		
	}
	
}
